<template>
  <div class="m-container">
    <el-row type="flex" justify="space-around" align="middle">
      <el-col :span="11">
        <div class="c-title">
          <span>调拨前</span>
        </div>
      </el-col>
      <el-col :span="2" />
      <el-col :span="11">
        <div class="c-title">
          <span>调拨后</span>
        </div>
      </el-col>
    </el-row>
    <el-row type="flex" justify="space-around" align="middle">
      <el-col :span="11" style="height: 100%">
        <div class="tran-box">
          <hk-table
            ref="hkTable"
            :table-data="propData.newData"
            :table-columns="propData.disList"
            :show-pag="false"
            :loading="loading"
            :dict-list="dictList"
            is-need-index
            :table-height="200" />
        </div>
      </el-col>
      <el-col :span="2" style="height: 100%">
        <div class="middle">
          <el-button icon="el-icon-arrow-right" size="mini" class="right" /></div
      ></el-col>
      <el-col :span="11" style="height: 100%">
        <div class="tran-box myform">
          <hk-form
            v-if="propData"
            ref="formRef"
            class="hk-flex"
            :data="formData"
            label-position="right"
            :rules="propData.rules"
            label-width="125"
            :btn-hidden="btnHidden"
            :dict-list="dictList"
            :form-labels="propData.labels">
            <template #filter-assetDepartmentId>
              <treeselect
                v-if="dictList.deptList"
                v-model="formData.assetDepartmentId"
                :options="dictList.deptList"
                :normalizer="normalizer"
                :append-to-body="true"
                placeholder="请选择责任部门"
                @select="changeOrg" />
            </template>
            <template #filter-ownerId>
              <el-select
                v-model="formData.ownerId"
                filterable
                 style="width: 100%;"
                placeholder="请选择责任人"
                size="12"
                :clearable="true"
              >
                <el-option v-for="item in dictList.userList" :key="item.id" :label="item.name" :value="item.id" />
              </el-select>
            </template>
          </hk-form>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import HkTable from '@/components/Hk-Table/index.vue'
import HkForm from '@/components/Hk-Form'
import { assetDict, userList } from '@/api/specialProject/asset'
import { treeSelect } from '@/api/specialProject/personnel'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
import Treeselect from '@riophae/vue-treeselect'
export default {
  // eslint-disable-next-line vue/no-unused-components
  components: { HkTable, HkForm, Treeselect },
  props: {
    propData: {
      type: Object,
      default: () => {},
    },
    labelPosition: {
      type: String,
      default: 'left',
    },
  },
  data() {
    return {
      // 表单数据
      formData: {},
      btnHidden: true,

      dictList: {
        userList: [],
        deptList: [],
        regionList: [],
      },
      loading: false,
      stagData: this.propData.selectData,
      isClear: false,
    }
  },
  created() {
    this.getdepts()
    this.getDicts()
  },
  mounted() {},
  methods: {
    /** 转换部门数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children
      }
      return {
        id: node.id,
        label: node.name,
        children: node.children,
      }
    },
    getDicts() {
      assetDict('deposit_region').then((res) => {
        this.dictList.regionList = res.map((o) => {
          o.label = o.name
          o.value = o.id
          return o
        })
      })
    },
    // 部门change事件
    changeOrg(node) {
      if (this.formData.ownerId) {
        this.formData.ownerId = null
      }
      this.getusers(node.id)
    },
    // 责任部门
    getdepts() {
      treeSelect().then((res) => {
        this.dictList.deptList = res
      })
    },
    // 查询责任人
    getusers(id) {
      userList({ orgId: id }).then((res) => {
        this.dictList.userList = res.map((i) => ({ name: i.name, id: i.id }))
      })
    },
    async submitForm() {
      const params = await this.$refs.formRef.handleFormSubmit('formLabels')
      Object.keys(params).forEach((key) => {
        for (var item of this.stagData) {
          item[key] = params[key]
        }
      })
      // this.$refs.formRef.handleFormSubmit('formLabels').then((res) => {
      console.log(params, this.stagData, 'sss')

      this.cancel()
      this.$emit('send', this.stagData)
    },
    cancel() {
      this.$refs.formRef.clearcheck('formLabels')
      this.close()
    },
    close() {
      this.$emit('close')
    },
  },
}
</script>
   <style lang="scss" scoped>
.middle {
  .right {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translateX(-50%) translateY(-50%);
  }
}
.c-title {
  padding: 20px 20px 0 20px;
  font-weight: 700;
}
#app.dark-theme {
  .m-container,
  .tab-content {
    background: transparent !important;
    color: #fff;
  }
  .tab-bg {
    background: rgba(59, 139, 255, 0.1) !important;
  }
  .sp-flex i {
    color: #4b6eef !important;
  }
  .active {
    border: 1px solid #fff !important;
    transform: scale(1.1, 1.1);
  }
}
.group-top-btn {
  display: flex;
  justify-content: flex-start;
  .group-middle {
    padding: 2px;
    margin: 2px;
    border: 1px solid transparent;
    border-radius: 6px;
    .group-btn {
      width: 30px;
      height: 30px;
      border-radius: 4px;
      cursor: pointer;
    }
  }
}
.active {
  border: 1px solid #4b6eef !important;
  transform: scale(1.1, 1.1);
}
.myform {
  display: flex;
  // justify-content: space-around;
  padding-right: 60px !important;
  padding-left: 0 !important;
  align-content: center;
}
.up-txt {
  font-size: 12px;
}
.add-row {
  margin-top: 20px;
}
.m-container {
  padding: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.tran-box {
  // background: #fff;
  border-radius: 4px;
  padding: 0 20px;
  min-height: 400px;
  margin-bottom: 20px;
}
.el-form {
  flex: 1;
  overflow: auto;
}
footer {
  height: 70px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 20px;
}
::v-deep .el-table__body-wrapper {
  height: 350px;
}

::v-deep {
  .el-button--text {
    padding: 0;
  }

  .el-input-group__append {
    background: transparent;
  }
}
</style>
      
      